/**
* 描述：职位管理
*/
<style lang="scss" scoped>
  @import 'src/styles/common';
  @import 'src/styles/company/index';
</style>
<template>
  <div class="content">
    <div class="com-main-title">
      <span class="tit">职位管理</span>
      <div class="clear"></div>
    </div>
    <div class="add-content" style="margin-top: 20px;">
      <Form ref="baseForm" :model="baseForm" :rules="baseFormRule" :label-width="180" class="main-add-1 formNoRadius01">
        <FormItem label="职位标题：" prop="title">
          <i-input v-model="baseForm.title"  placeholder="标题"></i-input>
        </FormItem>
        <FormItem label="职能类型：" prop="positionName">
          <i-input v-model="baseForm.positionName" :readonly="true" placeholder="职位的职务编号">
            <Button slot="append" icon="ios-search" @click="jobClassifyShow=true"></Button>
          </i-input>
        </FormItem>
        <!--<FormItem label="所在城市：" prop="cityId" style="width:370px;float: left;">-->
          <!--<Select v-model="baseForm.cityId" placeholder="所在城市" clearable filterable-->
                  <!--@on-change="changeCity(baseForm.cityId)" :disabled="true">-->
            <!--<template>-->
              <!--<i-option v-for="item in cityList" :value="item.id" :key="item.id">{{item.name}}</i-option>-->
            <!--</template>-->
          <!--</Select>-->
        <!--</FormItem>-->
        <!--<FormItem label="地区：" prop="districtId" :label-width="80" style="width:270px;float: left;">-->
          <!--<Select v-model="baseForm.districtId" :disabled="true" placeholder="地区" clearable filterable >-->
            <!--<template>-->
              <!--<i-option v-for="item in districtList" :value="item.id" :key="item.id">{{item.name}}</i-option>-->
            <!--</template>-->
          <!--</Select>-->
        <!--</FormItem>-->
        <!--<div class="clear"></div>-->
        <!--<FormItem label="职位地址：" prop="address">-->
          <!--<i-input v-model="baseForm.address" placeholder="职位所在地址" :disabled="true"></i-input>-->
        <!--</FormItem>-->
        <!--<Row>-->
          <!--<Col span="24">-->
            <!--<FormItem label="经度：" prop="latitude" style="width: 310px;float: left">-->
              <!--<i-input v-model="baseForm.latitude" :disabled="true" placeholder="经度"></i-input>-->
            <!--</FormItem>-->
            <!--<FormItem label="纬度：" prop="longitude" style="width: 290px;float: left" :label-width="150">-->
              <!--<i-input v-model="baseForm.longitude" :disabled="true" placeholder="纬度"></i-input>-->
            <!--</FormItem>-->
            <!--<div class="clear"></div>-->
          <!--</Col>-->
        <!--</Row>-->
        <Row>
          <Col span="12">
            <FormItem label="职位类型：" prop="type" style="width:300px;">
              <Select v-model="baseForm.type" placeholder="职位类型：" clearable filterable :readonly="isUpdate && baseForm.status !== 0">
                <template>
                  <i-option v-for="item in typeList" :value="item.value" :key="item.value">{{item.label}}</i-option>
                </template>
              </Select>
            </FormItem>
          </Col>
          <Col span="12">
            <FormItem label="学历：" prop="education" style="width:300px;">
              <Select v-model="baseForm.education" placeholder="学历：" clearable filterable>
                <template>
                  <i-option v-for="item in educationList" :value="item.value" :key="item.value">{{item.label}}</i-option>
                </template>
              </Select>
            </FormItem>
          </Col>
        </Row>
        <Row>
          <Col span="12">
            <FormItem label="工作经验要求：" prop="experience" style="width:300px;">
              <Select v-model="baseForm.experience" placeholder="工作经验要求：" clearable filterable>
                <template>
                  <i-option v-for="item in experienceList" :value="item.value" :key="item.value">{{item.label}}</i-option>
                </template>
              </Select>
            </FormItem>
          </Col>
          <Col span="12">
            <FormItem label="薪资：" prop="education" style="width:300px;">
              <Select v-model="baseForm.salary" placeholder="薪资：" clearable filterable>
                <template>
                  <i-option v-for="item in salaryList" :value="item.value" :key="item.value">{{item.label}}</i-option>
                </template>
              </Select>
            </FormItem>
          </Col>
        </Row>
        <FormItem label="招聘数量：" prop="demand">
          <!--<i-input v-model="baseForm.demand" placeholder="招聘数量">-->
            <Select v-model="baseForm.demand" placeholder="招聘数量：" clearable filterable>
              <template>
                <i-option v-for="item in demandList" :value="item.value" :key="item.value">{{item.label}}</i-option>
              </template>
            </Select>
        </FormItem>
        <FormItem label="职位诱惑：" prop="temptation">
          <i-input v-model="baseForm.temptation" type="textarea" :rows="4"  placeholder="职位诱惑"></i-input>
        </FormItem>
        <FormItem label="职位描述：" prop="description">
          <i-input v-model="baseForm.description" type="textarea" :rows="6"  placeholder="职位描述"></i-input>
        </FormItem>
        <div style="text-align: center">
          <i-button type="primary" size="large" @loading="addLoading" @click="addOrUpdate">提交修改</i-button>
          <i-button size="large" v-go-back>取消</i-button>
        </div>
      </Form>
    </div>
    <job-classify v-model="jobClassifyShow" v-on:jobData="jobData"></job-classify>
  </div>
</template>
<script>
  import { mapState, mapActions } from 'vuex';
  import { addFun, updateFun, getDetail } from '@/service/company/station/stationMService';
  import { district, districtByCityId, dictJobSearch } from '@/service/company/selectService/selectMService';
  import JobClassify from '@/components/common/jobClassify/jobClassify';
  export default {
    components: {
      JobClassify
    },
    computed: {
      ...mapState([
        'currentCompanyInfo'
      ])
    },
    data () {
      return {
        show: true,
        baseForm: {
          cityId: '',
          districtId: '',
          type: '',
          education: '',
          experience: ''
        },
        baseFormRule: {},
        cityList: [],
        districtList: [],
        typeList: [
          {value: 0, label: '全职'},
          {value: 1, label: '兼职'},
          {value: 2, label: '实习'}
        ],
        educationList: [
          {value: 0, label: '中专(高中)'},
          {value: 1, label: '大专'},
          {value: 2, label: '本科'},
          {value: 3, label: '硕士'},
          {value: 4, label: '博士'}
        ],
        experienceList: [
          {value: 0, label: '不限'},
          {value: 1, label: '1－3年'},
          {value: 2, label: '3－5年'},
          {value: 3, label: '5－10年'}
        ],
        salaryList: [
          {value: 0, label: '面议'},
          {value: 1, label: '1000-2000'},
          {value: 2, label: '2000-3000'},
          {value: 3, label: '3000-4000'},
          {value: 4, label: '4000-5000'},
          {value: 5, label: '5000-8000'},
          {value: 6, label: '8000-10000'},
          {value: 7, label: '10000-15000'},
          {value: 8, label: '15000-20000'},
          {value: 9, label: '20000-30000'},
          {value: 10, label: '30000-50000'},
          {value: 11, label: '50000-100000'},
          {value: 12, label: '100000以上'}
        ],
        demandList: [
          {value: 0, label: '若干'},
          {value: 1, label: '1人'},
          {value: 2, label: '2人'},
          {value: 3, label: '3人'},
          {value: 4, label: '4人'},
          {value: 5, label: '5人'},
          {value: 6, label: '6人'},
          {value: 7, label: '7人'},
          {value: 8, label: '8人'},
          {value: 9, label: '9人'},
          {value: 10, label: '10人'},
          {value: 11, label: '其他'}
        ],
        industryList: [],
        dictJobSearchList: [],
        title: '新增',
        isUpdate: false,
        addLoading: false,
        jobClassifyShow: false
      };
    },
    async created () {
      if (!this.currentCompanyInfo.name) await this.getCurrentComp();
      this.changeCity(this.currentCompanyInfo.cityId);
      this.getAllCityList();
      this.getDictJobSearchList();
      const res = this.$route.query;
      if (res.id) {
        this.isUpdate = true;
        await this.init(res.id);
      }
      this.baseForm.cityId = this.currentCompanyInfo.cityId;
      this.baseForm.districtId = this.currentCompanyInfo.districtId;
      this.baseForm.address = this.currentCompanyInfo.address;
      this.baseForm.latitude = this.currentCompanyInfo.latitude;
      this.baseForm.longitude = this.currentCompanyInfo.longitude;
    },
    mounted () {
    },
    methods: {
      ...mapActions([
        'getCurrentComp'
      ]),
      showJobs () {
          this.show = true;
      },
      async init (id) {
        this.title = '编辑';
        let result = await getDetail({id: id});
        this.baseForm = result.data;
        console.log(this.baseForm);
      },
      // 提交新增修改
      addOrUpdate () {
        this.$refs.baseForm.validate(async (valid) => {
          if (valid) {
            try {
              if (this.baseForm.demand) this.baseForm.demand = Number(this.baseForm.demand);
              this.addLoading = true;
              this.baseForm.industry = 1;
              if (this.title === '新增') {
                await addFun(this.baseForm);
              } else {
                console.log(this.baseForm);
                await updateFun({id: this.baseForm.id}, this.baseForm);
              }
              this.addLoading = false;
              this.$Notice.success({title: this.title + '成功'});
              this.$router.push({path: '/company/main/station'});
            } catch (e) {
              this.addInfoShow = false;
            }
          }
        });
      },
      // 获取全国城市集合
      async getAllCityList () {
        let result = await district({type: 10});
        this.cityList = result.data;
      },
      // 根据城市查询区
      async changeCity (code) {
        this.districtList = [];
        if (!code) return;
        let result = await districtByCityId({cityId: code});
        this.districtList = result.data;
      },
      async getDictJobSearchList () {
        let result = await dictJobSearch();
        this.dictJobSearchList = result.data;
      },
      jobData (jobData) {
        this.baseForm.position = jobData.id;
        this.baseForm.positionName = jobData.label;
      }
    }
  };
</script>
